public class LC541 {

    public String reverseStr(String s, int k) {
        int i=0,j=k-1;
        int count=0;
        char[] str=s.toCharArray();
        while(j<s.length()){
            while (i<j){
                char tmp=str[i];
                str[i]=str[j];
                str[j]=tmp;
                i++;
                j--;
            }
            count++;
            i=count*2*k;
            j=i+k-1;
        }
        if (i<s.length()){
            j=s.length()-1;
            while (i<j){
                char tmp=str[i];
                str[i]=str[j];
                str[j]=tmp;
                i++;
                j--;
            }
        }
        return new String(str);
    }

    public static void main(String[] args) {
        System.out.println(new LC541().reverseStr("hyzqyljrnigxvdtneasepfahmtyhlohwxmkqcdfehybknvdmfrfvtbsovjbdhevlfxpdaovjgunjqlimjkfnqcqnajmebeddqsgl",39));
    }

}
